//
//  RCDHttpTool.m
//  RCloudMessage
//
//  Created by Liv on 15/4/15.
//  Copyright (c) 2015年 RongCloud. All rights reserved.
//

#import "RCDHttpTool.h"
#import "AFHttpTool.h"
#import "HQUserInfo.h"
#import "RCDataBaseManager.h"
#import "HQGroupInfo.h"
#import "HQNoticeBody.h"
//#import "HQFans.h"


@implementation RCDHttpTool

+ (RCDHttpTool*)shareInstance
{
    static RCDHttpTool* instance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        instance = [[[self class] alloc] init];
        instance.allGroups = [NSMutableArray new];
    });
    return instance;
}
- (void)addFriendWithUserId:(NSString *)userId
                      token:(NSString *)token
                   friendId:(NSString*)friendId
                  addRemark:(NSString*)remark
                   complete:(void (^)(BOOL))result {
    [AFHttpTool requestFriend:userId token:token friendId:friendId addRemark:remark success:^(id response) {
        NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
        if (result) {
            if ([returnCode isEqualToString:@"00"]) {
                dispatch_async(dispatch_get_main_queue(), ^(void) {
                    result(YES);
                });
            }
        } else {
            result(NO);
        }
        
    } failure:^(id response) {
        NSLog(@"%@",response[@"message"]);
        if (result) {
            result(NO);
        }
    }];
    
}
#pragma mark 获取个人信息
- (void)getUserInfoByUid:(NSString *)uid
                   token:(NSString *)token
               searchUid:(NSString *)searchUid
              completion:(void (^)(RCUserInfo *))completion
{
        RCUserInfo *userInfo= [[RCDataBaseManager shareInstance] getUserByUserId:searchUid];
        if (userInfo==nil) {
    [AFHttpTool getUserInfoByUid:uid token:token searchUid:searchUid success:^(id response) {
        NSNumber *ok = response[@"ok"];;
        
        NSLog(@"==================贴ID%@",response[@"res"]);
        if (![ok isEqual:@0]) {
            
            NSDictionary *dic = response[@"res"];
            RCUserInfo *user = [RCUserInfo new];
            user.userId = ((NSNumber *)dic[@"uid"]).stringValue;
            if(dic[@"photo"]){
                user.portraitUri = HttpImgUrl(dic[@"photo"]);
            }
            if(dic[@"nickName"]){
              user.name = dic[@"nickName"];
            }
            [[RCDataBaseManager shareInstance] insertUserToDB:user];
            if (completion) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    completion(user);
                });
            }
        } else {
            RCUserInfo *user = [RCUserInfo new];
            user.userId = searchUid;
            user.portraitUri = @"";
            user.name = [NSString stringWithFormat:@"%@", searchUid];
            dispatch_async(dispatch_get_main_queue(), ^{
                completion(user);
            });
            
        }
        
    } failure:^(NSError *err) {
        NSLog(@"getUserInfoByUserID error");
        if (completion) {
            @try {
                dispatch_async(dispatch_get_main_queue(), ^{
                    RCUserInfo *user = [RCUserInfo new];  
                    user.userId = searchUid;
                    user.portraitUri = @"headerImageLogo";
                    user.name = [NSString stringWithFormat:@"%@", searchUid];
                    
                    completion(user);
                });
            }
            @catch (NSException *exception) {
                
            }
            @finally {
                
            }
            
        }
        
    }];
        } else {
            if (completion) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    completion(userInfo);
                });
            }
        }
}
- (void)getFriendInfoByUid:(NSString *)uid
                     token:(NSString *)token
                 searchUid:(NSString *)searchUid
                completion:(void (^)(MYAccountInfoObject *))completion
{
    [AFHttpTool getUserInfoByUid:uid token:token searchUid:searchUid success:^(id response) {
        NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
        if ([returnCode isEqualToString:@"00"]) {
            NSDictionary *dic = response[@"res"];
            MYAccountInfoObject *user = [MYAccountInfoObject new];
            user.attentionCnt = ((NSNumber *)dic[@"attentionCnt"]).integerValue;
            user.stImgName = dic[@"stImgName"];
            user.starType = dic[@"starType"];
            user.sex = ((NSNumber *)dic[@"sex"]).stringValue;
            user.collectionCnt = ((NSNumber *)dic[@"collectionCnt"]).integerValue;
            user.age =  ((NSNumber *)dic[@"age"]).stringValue;
            user.fansCnt = ((NSNumber *)dic[@"fansCnt"]).integerValue;
            user.headImg = dic[@"headImg"];
            user.myWords = dic[@"myWords"];
            user.nickName = dic[@"nickName"];
            user.uid = ((NSNumber *)dic[@"uid"]).stringValue;
            user.background = dic[@"background"];
            user.addStatus = dic[@"addStatus"];
            if ([dic.allKeys containsObject:@"address"]) {
                user.address = dic[@"address"];
            }else {
                user.address = @"未知的星球";
            }
            user.atteStatus = ((NSNumber *)dic[@"atteStatus"]).integerValue;
            
            
            if (completion) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    completion(user);
                });
            }
            
            
        } else {
            MYAccountInfoObject *user = [MYAccountInfoObject new];
            dispatch_async(dispatch_get_main_queue(), ^{
                completion(user);
            });
            
        }
        
    } failure:^(NSError *err) {
        NSLog(@"getUserInfoByUserID error");
        if (completion) {
            @try {
                dispatch_async(dispatch_get_main_queue(), ^{
                    MYAccountInfoObject *user = [MYAccountInfoObject new];
                    
                    
                    
                    completion(user);
                });
            }
            @catch (NSException *exception) {
                
            }
            @finally {
                
            }
            
        }
        
    }];
    
}
#pragma mark 好友列表+好友搜索
- (void)getFriendsWithUid:(NSString *)uid
                    token:(NSString *)token
                 keyWords:(NSString *)keyWords
                 pageSize:(NSInteger)pageSize
                  pageNum:(NSInteger)pageNum
                 complete:(void (^)(NSMutableArray *))friendList {
    NSMutableArray* list = [NSMutableArray new];
    [AFHttpTool getFriendListFromServerWithUid:uid
                                         token:token
                                      keyWords:keyWords
                                      pageSize:pageSize
                                       pageNum:pageNum
                                       success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (friendList) {
             if ([returnCode isEqualToString:@"00"]) {
                 [_allFriends removeAllObjects];
                 NSDictionary * responseDic = response[@"res"];
                 NSArray *responseArray = [self getFriendArray:responseDic];
                 [[RCDataBaseManager shareInstance] clearFriendsData];
                 for(int i = 0;i < responseArray.count;i++) {
                     NSDictionary *dic = [responseArray objectAtIndex:i];
                     HQUserInfo *userInfo = [HQUserInfo new];
                     userInfo.userId = ((NSNumber *)dic[@"uid"]).stringValue;
                     userInfo.portraitUri = dic[@"headImg"];
                     userInfo.name = dic[@"nickName"];
                     userInfo.addStatus = @"1";
                     userInfo.isSelected = NO;
                     [list addObject:userInfo];
                     [_allFriends addObject:userInfo];
                     RCUserInfo *user = [RCUserInfo new];
                     user.userId = ((NSNumber *)dic[@"uid"]).stringValue;
                     user.portraitUri = [dic objectForKey:@"headImg"];
                     user.name = [dic objectForKey:@"nickName"];
                     [[RCDataBaseManager shareInstance] insertUserToDB:user];
                     [[RCDataBaseManager shareInstance] insertFriendToDB:user];
                 }
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     friendList(list);
                 });
             }else{
                 friendList(list);
             }
         }
     }
                                       failure:^(NSError *err)
     {
         if (friendList) {
             NSMutableArray *cacheList=[[NSMutableArray alloc]initWithArray:[[RCDataBaseManager shareInstance] getAllFriends]];
             friendList(cacheList);
         }
     }];
}
- (NSArray *)getFriendArray:(NSDictionary*)dic {
    NSMutableArray *array = [NSMutableArray new];
    for (id key in [dic allKeys]) {
        [array addObjectsFromArray:dic[key]];
    }
    
    
    return [array copy];
}
#pragma mark 搜索好友
- (void)searchFriendWithUserId:(NSString *)userId
                         token:(NSString *)token
                      nickName:(NSString *)nickName
                       pageNum:(NSInteger)pageNum
                      pageSize:(NSInteger)pageSize
                      complete:(void (^)(NSMutableArray *))friendList
{
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool searchFriendWithUserId:userId
                                 token:token
                              nickName:nickName
                               pageNum:pageNum
                              pageSize:pageSize
                               success:^(id response) {
                                   NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
                                   if (friendList) {
                                       if ([returnCode isEqualToString:@"00"]) {
                                           NSArray * regDataArray = response[@"res"];
                                           for(int i = 0;i < regDataArray.count;i++) {
                                               NSDictionary *dic = [regDataArray objectAtIndex:i];
                                               HQUserInfo *userInfo = [HQUserInfo new];
                                               userInfo.userId = ((NSNumber *)dic[@"uid"]).stringValue;
                                               userInfo.portraitUri = dic[@"headImg"];
                                               userInfo.name = dic[@"nickName"];
                                               userInfo.applyStatus = dic[@"addStatus"];
                                               
                                               [list addObject:userInfo];
                                           }
                                           dispatch_async(dispatch_get_main_queue(), ^(void) {
                                               friendList(list);
                                           });
                                       } else {
                                           friendList(list);
                                       }
                                   }
                               }
                               failure:^(id response) {
                                   //  DDLogInfo(@"%@",response[@"message"]);
                                   if (friendList) {
                                       friendList(list);
                                   }
                               }];
    
}
#pragma mark 获取新朋友列表
- (void)getNewFriendListWithUid:(NSString *)uid
                          token:(NSString *)token
                       complete:(void (^)(NSMutableArray *))friendList {
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool getNewFriendListWithUid:uid
                                  token:token
                                success:^(id response) {
                                    
                                    NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
                                    if (friendList) {
                                        if ([returnCode isEqualToString:@"00"]) {
                                            NSArray * regDataArray = response[@"res"];
                                            for(int i = 0;i < regDataArray.count;i++) {
                                                NSDictionary *dic = [regDataArray objectAtIndex:i];
                                                HQUserInfo *userInfo = [HQUserInfo new];
                                                userInfo.userId = ((NSNumber *)dic[@"uid"]).stringValue;
                                                userInfo.portraitUri = dic[@"headImg"];
                                                userInfo.name = dic[@"nickName"];
                                                userInfo.applyStatus = dic[@"addStatus"];
                                                
                                                [list addObject:userInfo];
                                            }
                                            dispatch_async(dispatch_get_main_queue(), ^(void) {
                                                friendList(list);
                                            });
                                        } else {
                                            friendList(list);
                                        }
                                    }
                                    
                                }
                                failure:^(NSError *err) {
                                    if (friendList) {
                                        friendList(list);
                                    }
                                    
                                }];
    
    
}
#pragma mark 获取用户信息 更新本地数据库
- (void)updateUserInfoByUid:(NSString *)uid
                      token:(NSString *)token
                  searchUid:(NSString *)searchUid
                    success:(void (^)(RCUserInfo *))success
                    failure:(void (^)(NSError *))failure {
    [AFHttpTool getUserInfoByUid:uid
                           token:token
                       searchUid:searchUid
                         success:^(id response) {
                             if (response) {
                                 NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
                                 if ([returnCode isEqualToString:@"00"]) {
                                     NSDictionary *dic = response[@"res"];
                                     RCUserInfo *user = [RCUserInfo new];
                                     user.userId = ((NSNumber *)dic[@"uid"]).stringValue;
                                     user.portraitUri = dic[@"headImg"];
                                     user.name = dic[@"nickName"];
                                     [[RCDataBaseManager shareInstance] insertUserToDB:user];
                                     if (success) {
                                         dispatch_async(dispatch_get_main_queue(), ^{
                                             success(user);
                                         });
                                     }
                                     
                                 } 
                                 
                             }
                             
                         }
                         failure:^(NSError *err) {
                             
                         }];
    
}
#pragma 图片上传
- (void)uploadImageWith:(UIImage *)img
              imgBelong:(NSString *)imgBelong
                success:(void (^)(NSString *))success
                failure:(void (^)(NSError *))failure
{
    [AFHttpTool uploadImageWith:img
                      imgBelong:imgBelong
                        success:^(id response)
     {
         if (response) {
             NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
             if ([returnCode isEqualToString:@"00"]) {
                 NSString *responseStr = response[@"res"];
                 if (success) {
                     dispatch_async(dispatch_get_main_queue(), ^{
                         success(responseStr);
                     });
                 }
             }
         }
         
     }
                        failure:^(NSError *err) {
                            // DDLogInfo(@"%@",err);
                            
                        }];
    
}
#pragma mark 创建群组
- (void)createGroupWithUid:(NSString *)uid
                     token:(NSString *)token
              groupUsersId:(NSString *)groupUsersId
                  groupImg:(NSString *)groupImg
                 groupName:(NSString *)groupName
                   success:(void (^)(NSString *))success
                   failure:(void (^)(NSError *))failure {
    [AFHttpTool createGroupWithUid:uid
                             token:token
                      groupUsersId:groupUsersId
                          groupImg:groupImg
                         groupName:groupName
                           success:^(id response) {
                               if (response) {
                                   NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
                                   if ([returnCode isEqualToString:@"00"]) {
                                       NSNumber *responseStr = response[@"res"][@"groupId"];
                                       NSString *groupIdString = responseStr.stringValue;
                                       if (success) {
                                           dispatch_async(dispatch_get_main_queue(), ^{
                                               success(groupIdString);
                                           });
                                       }
                                   }
                                   
                               }
                           }
                           failure:^(NSError *err) {
                               NSLog(@"%@",err);
                               
                           }];
}
#pragma mark 获取群信息
- (void)getGroupInfoByUid:(NSString *)uid
                    token:(NSString *)token
                  groupId:(NSString *)groupId
        successCompletion:(void (^)(RCGroup *))completion
{
    [AFHttpTool getGroupInfoByUid:uid
                            token:token
                          groupId:groupId
                          success:^(id response) {
                              NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
                              NSDictionary *result = response[@"res"];
                              if ([returnCode isEqualToString:@"00"]&&result) {
                                  HQGroupInfo *group = [HQGroupInfo new];
                                  group.groupId = [NSString stringWithFormat:@"%@",result[@"groupId"]];
                                  group.groupName = result[@"groupName"];
                                  group.portraitUri = result[@"groupImg"];
                                  group.createId = result[@"createUid"];
                                  if ([group.groupId isEqualToString:groupId] && completion) {
                                      
                                      completion(group);
                                  }
                                  
                              }
                              
                          }
                          failure:^(NSError *err) {
                              
                          }];
}
#pragma  mark 删除好友
- (void)deleteFriendByUid:(NSString *)uid
                    token:(NSString *)token
                 friendId:(NSString *)friendId
                 complete:(void (^)(BOOL))result;
{
    [AFHttpTool deleteFriendByUid:uid
                            token:token
                         friendId:friendId
                          success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 [[RCDataBaseManager shareInstance]deleteFriendFromDB:friendId];
             } else {
                 result(NO);
             }
         }
         
     }
                          failure:^(NSError *err)
     {
         if (result) {
             result(NO);
         }
     }];
    
}
#pragma mark 查询群成员列表
- (void)getGroupMemberListByUid:(NSString *)uid
                          token:(NSString *)token
                        groupId:(NSString *)groupId
                       complete:(void (^)(NSMutableArray *))memberList
{
    NSMutableArray *list = [NSMutableArray new];
    
    [AFHttpTool getGroupMemberListByUid:uid
                                  token:token
                                groupId:groupId
                                success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (memberList) {
             if ([returnCode isEqualToString:@"00"]) {
                 NSArray * regDataArray = response[@"res"];
                 for(int i = 0;i < regDataArray.count;i++) {
                     NSDictionary *dic = [regDataArray objectAtIndex:i];
                     RCUserInfo *userInfo = [RCUserInfo new];
                     userInfo.userId = ((NSNumber *)dic[@"uid"]).stringValue;
                     userInfo.portraitUri = dic[@"headImg"];
                     userInfo.name = dic[@"nickName"];
                     [list addObject:userInfo];
                 }
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     memberList(list);
                 });
             } else {
                 memberList(list);
             }
             
         }
     }
                                failure:^(NSError *err)
     {
         if (memberList) {
             memberList(list);
         }
     }];
}
#pragma mark 更新群接口
- (void)updateGroupByUid:(NSString *)uid
                   token:(NSString *)token
                 groupId:(NSString *)groupId
            WithGroupImg:(NSString *)groupImg
               groupName:(NSString *)groupName
                complete:(void (^)(BOOL))result
{
    [AFHttpTool updateGroupByUid:uid
                           token:token
                         groupId:groupId
                    WithGroupImg:groupImg
                       groupName:groupName
                         success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 
             } else {
                 result(NO);
             }
         }
         
     }
                         failure:^(NSError *err) {
                             if (result) {
                                 result(NO);
                             }
                         }];
    
}
#pragma mark 管理权转让
- (void)attornGroupMgrByUid:(NSString *)uid
                      token:(NSString *)token
                    groupId:(NSString *)groupId
              withCreateUid:(NSString *)createUid
                   complete:(void (^)(BOOL))result
{
    [AFHttpTool attornGroupMgrByUid:uid
                              token:token
                            groupId:groupId
                      withCreateUid:createUid
                            success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 
             } else {
                 result(NO);
             }
         }
         
     }
                            failure:^(NSError *err)
     {
         if (result) {
             result(NO);
         }
     }];
    
}
#pragma mark 群成员变动
- (void)updateGroupMemberByUid:(NSString *)uid
                         token:(NSString *)token
                       groupId:(NSString *)groupId
                  withOperType:(NSString *)operType
                   groupUserId:(NSString *)groupUserId
                      complete:(void (^)(BOOL))result
{
    [AFHttpTool updateGroupMemberByUid:uid
                                 token:token
                               groupId:groupId
                          withOperType:operType
                           groupUserId:groupUserId
                               success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 
             } else {
                 result(NO);
             }
         }
         
     }
                               failure:^(NSError *err) {
                                   if (result) {
                                       result(NO);
                                   }
                               }];
}
#pragma mark 退出群
- (void)quitGroupByUid:(NSString *)uid
                 token:(NSString *)token
               groupId:(NSString *)groupId
              complete:(void (^)(BOOL))result
{
    [AFHttpTool quitGroupByUid:uid
                         token:token
                       groupId:groupId
                       success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 
             } else {
                 result(NO);
             }
         }
     }
                       failure:^(NSError *err)
     {
         if (result) {
             result(NO);
         }
     }];
}
#pragma mark 清空好友列表
- (void)cleanNewFriendsApplyListByUid:(NSString *)uid
                                token:(NSString *)token
                           userIdSets:(NSString *)userIdSets
                             complete:(void (^)(BOOL))result
{
    [AFHttpTool cleanNewFriendsApplyListByUid:uid
                                        token:token
                                   userIdSets:userIdSets
                                      success:^(id response) {
                                          NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
                                          if (result) {
                                              if ([returnCode isEqualToString:@"00"]) {
                                                  dispatch_async(dispatch_get_main_queue(), ^(void) {
                                                      result(YES);
                                                  });
                                                  
                                              } else {
                                                  result(NO);
                                              }
                                          }
                                      }
                                      failure:^(NSError *err) {
                                          if (result) {
                                              result(NO);
                                          }
                                      }];
}
#pragma mark 查询我的群组
- (void)getMyGroupsByUid:(NSString *)uid
                   token:(NSString *)token
                complete:(void (^)(NSMutableArray *))groupListArray
{
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool getMyGroupsByUid:uid
                           token:token
                         success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (groupListArray) {
             if ([returnCode isEqualToString:@"00"]) {
                 NSArray * regDataArray = response[@"res"];
                 for(int i = 0;i < regDataArray.count;i++) {
                     NSDictionary *dic = [regDataArray objectAtIndex:i];
                     HQGroupInfo *groupInfo = [HQGroupInfo new];
                     NSNumber *memCount = [dic objectForKey:@"memCount"];
                     NSNumber *memTotal = [dic objectForKey:@"memTotal"];
                     NSNumber *groupId = [dic objectForKey:@"groupId"];
                     groupInfo.groupId = groupId.stringValue;
                     groupInfo.groupName = dic[@"groupName"];
                     groupInfo.portraitUri = dic[@"groupImg"];
                     groupInfo.memCount = memCount.integerValue;
                     groupInfo.memTotal = memTotal.integerValue;
                     
                     [list addObject:groupInfo];
                 }
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     groupListArray(list);
                 });
             } else {
                 groupListArray(list);
             }
             
         }
     }
                         failure:^(NSError *err)
     {
         if (groupListArray) {
             groupListArray(list);
         }
         
     }];
    
}
#pragma mark 查询注册用户
- (void)searchRegUsersListByUid:(NSString *)uid
                          token:(NSString *)token
                    phoneNumber:(NSString *)phoneNumber
                       complete:(void (^)(NSMutableArray *))userList
{
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool searchRegUsersListByUid:uid
                                  token:token
                            phoneNumber:phoneNumber
                                success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (userList) {
             if ([returnCode isEqualToString:@"00"]) {
                 NSArray * regDataArray = response[@"res"];
                 for(int i = 0;i < regDataArray.count;i++) {
                     NSDictionary *dic = [regDataArray objectAtIndex:i];
                     HQUserInfo *userInfo = [HQUserInfo new];
                     NSNumber *uid = dic[@"uid"];
                     userInfo.userId = uid.stringValue;
                     userInfo.name = dic[@"nickName"];
                     userInfo.portraitUri = dic[@"headImg"];
                     NSNumber *isReg = dic[@"isReg"];
                     userInfo.isReg = isReg.boolValue;
                     NSNumber *addStatus = dic[@"addStatus"];
                     userInfo.addStatus = addStatus.stringValue;
                     userInfo.phoneNum = dic[@"telephone"];
                     [list addObject:userInfo];
                 }
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     userList(list);
                 });
             } else {
                 userList(list);
             }
         }
         
         
     }
                                failure:^(NSError *err)
     {
         if (userList) {
             userList(list);
         }
         
     }];
}
#pragma mark 获取通知会话
- (void)getFirstNotificationByUid:(NSString *)uid
                            token:(NSString *)token
                successCompletion:(void (^)(HQMessage *))completion
{
    [AFHttpTool getFirstNotificationByUid:uid
                                    token:token
                                  success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         NSDictionary *dic = response[@"res"];
         if ([returnCode isEqualToString:@"00"]&&[dic count] != 0) {
             HQMessage *message = [HQMessage new];
             NSNumber *messageId = dic[@"msgId"];
             message.messageId = messageId.stringValue;
             NSNumber *noticeType = dic[@"noticeType"];
             message.noticeType = noticeType.stringValue;
             message.title = dic[@"title"];
             message.createTime = dic[@"createTime"];
             message.noticeImg = dic[@"noticeImg"];
             if (completion) {
                 completion(message);
             }
             
         }
         
     }
                                  failure:^(NSError *err) {
                                      
                                  }];
    
}
#pragma mark 获取评论信息列表
- (void)getCommentMsgsListByUid:(NSString *)uid
                          token:(NSString *)token
                          msgId:(NSString *)msgId
                       complete:(void (^)(NSMutableArray *))commentList

{
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool getCommentMsgsListByUid:uid
                                  token:token
                                  msgId:msgId
                                success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (commentList) {
             if ([returnCode isEqualToString:@"00"]) {
                 NSArray *dataArray =  response[@"res"];
                 for (int i = 0; i < dataArray.count; i++) {
                     NSDictionary *dic = [dataArray objectAtIndex:i];
                     HQNoticeBody *noticeBody = [HQNoticeBody new];
                     noticeBody.comment = dic[@"comment"];
                     NSNumber *commentId = dic[@"commentId"];
                     noticeBody.commentId = commentId.integerValue;
                     
                     noticeBody.createTime = dic[@"createTime"];
                     if ([dic.allKeys containsObject:@"footmark"]) {
                         NSDictionary *fDic = dic[@"footmark"];
                         HQFootmark *footmark = [HQFootmark new];
                         footmark.content = fDic[@"content"];
                         footmark.fCreateTime = fDic[@"createTime"];
                         NSNumber *footId = fDic[@"footmarkId"];
                         footmark.footmarkId = footId.integerValue;
                         footmark.fAvatarImage = fDic[@"headImg"];
                         NSNumber *type = fDic[@"mediaType"];
                         footmark.mediaType = type.integerValue;
                         footmark.fName = fDic[@"nickName"];
                         footmark.prevImgUrl = fDic[@"prevImgUrl"];
                         
                         footmark.fuid = ((NSNumber*)fDic[@"uid"]).stringValue;
                         NSString *imageStrArray = fDic[@"urls"];
                         footmark.photoArray = [imageStrArray componentsSeparatedByString:@","];
                         noticeBody.fmodel = footmark;
                     }
                     if ([dic.allKeys containsObject:@"photo"]) {
                         NSDictionary *fDic = dic[@"photo"];
                         HQFootmark *footmark = [HQFootmark new];
                         footmark.content = fDic[@"content"];
                         footmark.fCreateTime = fDic[@"createTime"];
                         NSNumber *footId = fDic[@"photoId"];
                         footmark.footmarkId = footId.integerValue;
                         footmark.fAvatarImage = fDic[@"headImg"];
                         footmark.fName = fDic[@"nickName"];
                         NSNumber *type = fDic[@"mediaType"];
                         footmark.mediaType = type.integerValue;
                         footmark.fuid = ((NSNumber*)fDic[@"uid"]).stringValue;
                         NSString *imageStrArray = fDic[@"urls"];
                         footmark.photoArray = [imageStrArray componentsSeparatedByString:@","];
                         noticeBody.fmodel = footmark;
                     }
                     if ([dic.allKeys containsObject:@"video"]) {
                         NSDictionary *fDic = dic[@"video"];
                         HQFootmark *footmark = [HQFootmark new];
                         footmark.content = fDic[@"content"];
                         footmark.fCreateTime = fDic[@"createTime"];
                         NSNumber *footId = fDic[@"videoId"];
                         footmark.footmarkId = footId.integerValue;
                         footmark.fAvatarImage = fDic[@"headImg"];
                         footmark.fName = fDic[@"nickName"];
                         footmark.prevImgUrl = fDic[@"prevImgUrl"];
                         NSNumber *type = fDic[@"mediaType"];
                         footmark.mediaType = type.integerValue;
                         
                         footmark.fuid = ((NSNumber*)fDic[@"uid"]).stringValue;
                         noticeBody.fmodel = footmark;
                     }
                     
                     noticeBody.headImg = dic[@"headImg"];
                     noticeBody.name = dic[@"nickName"];
                     noticeBody.type = ((NSNumber *)dic[@"type"]).integerValue;
                     noticeBody.uid = ((NSNumber*)dic[@"uid"]).stringValue;
                     
                     [list addObject:noticeBody];
                 }
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     commentList(list);
                 });
             } else {
                 commentList(list);
             }
             
         }
         
     }
                                failure:^(NSError *err)
     {
         if (commentList) {
             commentList(list);
         }
         
     }];
    
}
#pragma mark 获取回复信息列表
- (void)getFcommentMsgsListByUid:(NSString *)uid
                           token:(NSString *)token
                           msgId:(NSString *)msgId
                        complete:(void (^)(NSMutableArray *))fcommentList
{
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool getFcommentMsgsListByUid:uid
                                   token:token
                                   msgId:msgId
                                 success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (fcommentList) {
             if ([returnCode isEqualToString:@"00"]) {
                 NSArray *dataArray =  response[@"res"];
                 for (int i = 0; i < dataArray.count; i++) {
                     NSDictionary *dic = [dataArray objectAtIndex:i];
                     HQNoticeBody *noticeBody = [HQNoticeBody new];
                     NSNumber *commentId = dic[@"fcommentId"];
                     noticeBody.commentId = commentId.integerValue;
                     noticeBody.comment = dic[@"comment"];
                     noticeBody.createTime = dic[@"createTime"];
                     if ([dic.allKeys containsObject:@"footmark"]) {
                         NSDictionary *fDic = dic[@"footmark"];
                         HQFootmark *footmark = [HQFootmark new];
                         footmark.content = fDic[@"content"];
                         footmark.fCreateTime = fDic[@"createTime"];
                         NSNumber *footId = fDic[@"footmarkId"];
                         footmark.footmarkId = footId.integerValue;
                         footmark.fAvatarImage = fDic[@"headImg"];
                         NSNumber *type = fDic[@"mediaType"];
                         footmark.mediaType = type.integerValue;
                         footmark.fName = fDic[@"nickName"];
                         footmark.prevImgUrl = fDic[@"prevImgUrl"];
                         NSDictionary *commentDic = fDic[@"commentInfo"];
                         HQCommentInfo *commentInfo = [HQCommentInfo new];
                         commentInfo.comment = commentDic[@"comment"];
                         NSNumber *commentId = commentDic[@"commentId"];
                         commentInfo.commentId = commentId.integerValue;
                         commentInfo.createTime = commentDic[@"createTime"];
                         commentInfo.nickName = commentDic[@"nickName"];
                         commentInfo.targetId = ((NSNumber *)commentDic[@"targetId"]).stringValue;
                         commentInfo.uid = ((NSNumber *)commentDic[@"uid"]).stringValue;
                         NSMutableArray *fcommentListArray = [NSMutableArray new];
                         for (NSDictionary *fcommentDic in commentDic[@"fcommentList"]) {
                             HQFcommentList *list = [HQFcommentList new];
                             list.nickName = fcommentDic[@"nickName"];
                             list.targetNickName = fcommentDic[@"targetNickName"];
                             list.comment = fcommentDic[@"comment"];
                             [fcommentListArray addObject:list];
                         }
                         commentInfo.fcommentListArray = fcommentListArray;
                         footmark.commentInfo = commentInfo;
                         
                         footmark.fuid = ((NSNumber*)fDic[@"uid"]).stringValue;
                         NSString *imageStrArray = fDic[@"urls"];
                         footmark.photoArray = [imageStrArray componentsSeparatedByString:@","];
                         noticeBody.fmodel = footmark;
                     }
                     if ([dic.allKeys containsObject:@"photo"]) {
                         NSDictionary *fDic = dic[@"photo"];
                         HQFootmark *footmark = [HQFootmark new];
                         footmark.content = fDic[@"content"];
                         footmark.fCreateTime = fDic[@"createTime"];
                         NSNumber *footId = fDic[@"photoId"];
                         footmark.footmarkId = footId.integerValue;
                         footmark.fAvatarImage = fDic[@"headImg"];
                         footmark.fName = fDic[@"nickName"];
                         NSNumber *type = fDic[@"mediaType"];
                         footmark.mediaType = type.integerValue;
                         footmark.fuid = ((NSNumber*)fDic[@"uid"]).stringValue;
                         NSString *imageStrArray = fDic[@"urls"];
                         footmark.photoArray = [imageStrArray componentsSeparatedByString:@","];
                         NSDictionary *commentDic = fDic[@"commentInfo"];
                         HQCommentInfo *commentInfo = [HQCommentInfo new];
                         commentInfo.comment = commentDic[@"comment"];
                         NSNumber *commentId = commentDic[@"commentId"];
                         commentInfo.commentId = commentId.integerValue;
                         commentInfo.createTime = commentDic[@"createTime"];
                         commentInfo.nickName = commentDic[@"nickName"];
                         commentInfo.targetId = ((NSNumber *)commentDic[@"targetId"]).stringValue;
                         commentInfo.uid = ((NSNumber *)commentDic[@"uid"]).stringValue;
                         NSMutableArray *fcommentListArray = [NSMutableArray new];
                         for (NSDictionary *fcommentDic in commentDic[@"fcommentList"]) {
                             HQFcommentList *list = [HQFcommentList new];
                             list.nickName = fcommentDic[@"nickName"];
                             list.targetNickName = fcommentDic[@"targetNickName"];
                             list.comment = fcommentDic[@"comment"];
                             [fcommentListArray addObject:list];
                         }
                         commentInfo.fcommentListArray = fcommentListArray;
                         footmark.commentInfo = commentInfo;
                         noticeBody.fmodel = footmark;
                     }
                     if ([dic.allKeys containsObject:@"video"]) {
                         NSDictionary *fDic = dic[@"video"];
                         HQFootmark *footmark = [HQFootmark new];
                         footmark.content = fDic[@"content"];
                         footmark.fCreateTime = fDic[@"createTime"];
                         NSNumber *footId = fDic[@"videoId"];
                         footmark.footmarkId = footId.integerValue;
                         footmark.fAvatarImage = fDic[@"headImg"];
                         footmark.fName = fDic[@"nickName"];
                         footmark.prevImgUrl = fDic[@"prevImgUrl"];
                         NSNumber *type = fDic[@"mediaType"];
                         footmark.mediaType = type.integerValue;
                         NSString *imageStrArray = fDic[@"urls"];
                         footmark.photoArray = [imageStrArray componentsSeparatedByString:@","];
                         
                         footmark.fuid = ((NSNumber*)fDic[@"uid"]).stringValue;
                         NSDictionary *commentDic = fDic[@"commentInfo"];
                         HQCommentInfo *commentInfo = [HQCommentInfo new];
                         commentInfo.comment = commentDic[@"comment"];
                         NSNumber *commentId = commentDic[@"commentId"];
                         commentInfo.commentId = commentId.integerValue;
                         commentInfo.createTime = commentDic[@"createTime"];
                         commentInfo.nickName = commentDic[@"nickName"];
                         commentInfo.targetId = ((NSNumber *)commentDic[@"targetId"]).stringValue;
                         commentInfo.uid = ((NSNumber *)commentDic[@"uid"]).stringValue;
                         NSMutableArray *fcommentListArray = [NSMutableArray new];
                         for (NSDictionary *fcommentDic in commentDic[@"fcommentList"]) {
                             HQFcommentList *list = [HQFcommentList new];
                             list.nickName = fcommentDic[@"nickName"];
                             list.targetNickName = fcommentDic[@"targetNickName"];
                             list.comment = fcommentDic[@"comment"];
                             [fcommentListArray addObject:list];
                         }
                         commentInfo.fcommentListArray = fcommentListArray;
                         footmark.commentInfo = commentInfo;
                         noticeBody.fmodel = footmark;
                     }
                     
                     noticeBody.headImg = dic[@"headImg"];
                     noticeBody.name = dic[@"nickName"];
                     noticeBody.type = ((NSNumber *)dic[@"type"]).integerValue;
                     noticeBody.uid = ((NSNumber*)dic[@"uid"]).stringValue;
                     
                     [list addObject:noticeBody];
                 }
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     fcommentList(list);
                 });
             }else {
                 fcommentList(list);
             }
             
         }
         
     }
                                 failure:^(NSError *err)
     {
         if (fcommentList) {
             fcommentList(list);
         }
         
     }];
}
#pragma mark 查看点赞列表
- (void)getLikeMsgListByUid:(NSString *)uid
                      token:(NSString *)token
                      msgId:(NSString *)msgId
                   complete:(void (^)(NSMutableArray *))flikeList
{
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool getLikeMsgListByUid:uid
                              token:token
                              msgId:msgId
                            success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (flikeList) {
             if ([returnCode isEqualToString:@"00"]) {
                 NSArray *dataArray = response[@"res"];
                 for (NSDictionary *dic in dataArray) {
                     HQNoticeBody *noticeBody = [HQNoticeBody new];
                     noticeBody.createTime = dic[@"createTime"];
                     noticeBody.headImg = dic[@"headImg"];
                     noticeBody.uid = ((NSNumber *)dic[@"uid"]).stringValue;
                     noticeBody.name = dic[@"nickName"];
                     noticeBody.comment = @"赞了我";
                     NSNumber *type = dic[@"type"];
                     
                     noticeBody.type = type.integerValue;
                     NSNumber *cmTargetType = dic[@"cmTargetType"];
                     noticeBody.cmTargetType = cmTargetType.integerValue;
                     if ([dic.allKeys containsObject:@"footmark"])  {
                         NSDictionary *fDic = dic[@"footmark"];
                         HQFootmark *footmark = [self getFModelByDic:fDic type:type cmTargetType:cmTargetType];
                         noticeBody.fmodel = footmark;
                     }
                     if ([dic.allKeys containsObject:@"photo"]) {
                         NSDictionary *fDic = dic[@"photo"];
                         HQFootmark *footmark = [self getFModelByDic:fDic type:type cmTargetType:cmTargetType];
                         noticeBody.fmodel = footmark;
                     }
                     if ([dic.allKeys containsObject:@"video"]) {
                         NSDictionary *fDic = dic[@"video"];
                         HQFootmark *footmark = [self getFModelByDic:fDic type:type cmTargetType:cmTargetType];
                         noticeBody.fmodel = footmark;
                     }
                     [list addObject:noticeBody];
                     
                 }
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     flikeList(list);
                 });
                 
             }
             else {
                 flikeList(list);
             }
         }
         
         
     }
                            failure:^(NSError *err)
     {
         if (flikeList) {
             flikeList(list);
         }
         
     }];
    
}
- (HQFootmark *)getFModelByDic:(NSDictionary *)fDic
                          type:(NSNumber *)type
                  cmTargetType:(NSNumber *)cmTargetType
{
    HQFootmark *footmark = [HQFootmark new];
    footmark.content = fDic[@"content"];
    footmark.fCreateTime = fDic[@"createTime"];
    NSNumber *footId = nil;
    if (type.integerValue == 1) {
        footId = fDic[@"photoId"];
    } else if (type.integerValue == 2) {
        footId = fDic[@"videoId"];
    } else if (type.integerValue == 3) {
        footId = fDic[@"footmarkId"];
    } else  {
        if (cmTargetType.integerValue == 1) {
             footId = fDic[@"photoId"];
        }else if (cmTargetType.integerValue == 2) {
             footId = fDic[@"videoId"];
        } else {
           footId = fDic[@"footmarkId"];
        }
        
    }
    
    footmark.footmarkId = footId.integerValue;
    footmark.fAvatarImage = fDic[@"headImg"];
    NSNumber *mediaType = fDic[@"mediaType"];
    footmark.mediaType = mediaType.integerValue;
    footmark.fName = fDic[@"nickName"];
    footmark.prevImgUrl = fDic[@"prevImgUrl"];
    footmark.fuid = ((NSNumber*)fDic[@"uid"]).stringValue;
    NSString *imageStrArray = fDic[@"urls"];
    footmark.photoArray = [imageStrArray componentsSeparatedByString:@","];
    if ([type.stringValue isEqualToString:@"4"]||[type.stringValue isEqualToString:@"5"]) {
        NSDictionary *commentDic = fDic[@"commentInfo"];
        HQCommentInfo *commentInfo = [HQCommentInfo new];
        commentInfo.comment = commentDic[@"comment"];
        NSNumber *commentId = commentDic[@"commentId"];
        commentInfo.commentId = commentId.integerValue;
        commentInfo.createTime = commentDic[@"createTime"];
        commentInfo.nickName = commentDic[@"nickName"];
        commentInfo.targetId = ((NSNumber *)commentDic[@"targetId"]).stringValue;
        commentInfo.uid = ((NSNumber *)commentDic[@"uid"]).stringValue;
        if ([type.stringValue isEqualToString:@"5"]) {
            NSMutableArray *fcommentListArray = [NSMutableArray new];
            for (NSDictionary *fcommentDic in commentDic[@"fcommentList"]) {
                HQFcommentList *list = [HQFcommentList new];
                list.nickName = fcommentDic[@"nickName"];
                list.targetNickName = fcommentDic[@"targetNickName"];
                list.comment = fcommentDic[@"comment"];
                [fcommentListArray addObject:list];
            }
            commentInfo.fcommentListArray = fcommentListArray;
            
        }
        footmark.commentInfo = commentInfo;
        
    }
    return footmark;
    
}
#pragma mark 添加回复
- (void)addCommentByUid:(NSString *)uid
                  token:(NSString *)token
              commentId:(NSInteger)commentId
               targetId:(NSString *)targetId
            withComment:(NSString *)comment
               complete:(void (^)(BOOL))result
{
    [AFHttpTool addCommentByUid:uid
                          token:token
                      commentId:commentId
                       targetId:targetId
                    withComment:comment
                        success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 
             } else {
                 result(NO);
             }
         }
         
     }
                        failure:^(NSError *err)
     {
         if (result) {
             result(NO);
         }
         
     }];
    
}
#pragma mark 查询粉丝列表
- (void)queryFansListByUid:(NSString *)uid token:(NSString *)token seachUid:(NSString *)seachUid pageSize:(NSString *)pageSize pageNum:(NSString *)pageNum complete:(void (^)(NSMutableArray *))fansListArray {
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool queryFansListByUid:uid
                             token:token
                          seachUid:seachUid
                          pageSize:pageSize
                           pageNum:pageNum
                           success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (fansListArray) {
             if ([returnCode isEqualToString:@"00"]) {
//                 NSArray *dataArray = response[@"res"];
//                 for (NSDictionary * dic in dataArray) {
//                     
//                     
//                 }
                 dispatch_async(dispatch_get_main_queue(), ^{
                     fansListArray(list);
                 });
                 
             } else {
                 fansListArray(list);
             }
         }
         
         
     }
                           failure:^(NSError *err)
     {
         if (fansListArray) {
             fansListArray(list);
         }
         
     }];
}
#pragma mark 添加关注
- (void)addAttenByUid:(NSString *)uid token:(NSString *)token attentionUid:(NSString *)attentionUid complete:(void (^)(BOOL))result {
    [AFHttpTool addAttenByUid:uid token:token attentionUid:attentionUid success:^(id response) {
        NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
        if (result) {
            if ([returnCode isEqualToString:@"00"]) {
                dispatch_async(dispatch_get_main_queue(), ^(void) {
                    result(YES);
                });
                
            } else {
                result(NO);
            }
        }
    } failure:^(NSError *err) {
        if (result) {
            result(NO);
        }
    }];
}
#pragma mark 查询关注列表
- (void)queryAttenListByUid:(NSString *)uid token:(NSString *)token seachUid:(NSString *)seachUid pageSize:(NSString *)pageSize pageNum:(NSString *)pageNum complete:(void (^)(NSMutableArray *))concernListArray {
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool queryAttenListByUid:uid token:token seachUid:seachUid pageSize:pageSize pageNum:pageNum success:^(id response) {
        NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
        if (concernListArray) {
            if ([returnCode isEqualToString:@"00"]) {
//                NSArray *dataArray = response[@"res"];
//                for (NSDictionary * dic in dataArray) {
//                    HQFans *fanModel = [HQFans new];
//                    fanModel.atteStatus = ((NSNumber *)dic[@"atteStatus"]).integerValue;
//                    fanModel.headImg = dic[@"headImg"];
//                    fanModel.FansUid = ((NSNumber *)dic[@"uid"]).stringValue;
//                    fanModel.address = dic[@"address"];
//                    fanModel.nickName = dic[@"nickName"];
//                    [list addObject:fanModel];
//                    
//                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    concernListArray(list);
                });
                
            } else {
                concernListArray(list);
            }
        }
        
        
        
    } failure:^(NSError *err) {
        if (concernListArray) {
            concernListArray(list);
        }
        
    }];
    
}
#pragma mark 取消关注
- (void)delAttenByUid:(NSString *)uid token:(NSString *)token attentionUid:(NSString *)attentionUid complete:(void (^)(BOOL))result {
    [AFHttpTool delAttenByUid:uid token:token attentionUid:attentionUid success:^(id response) {
        NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
        if (result) {
            if ([returnCode isEqualToString:@"00"]) {
                dispatch_async(dispatch_get_main_queue(), ^(void) {
                    result(YES);
                });
                
            } else {
                result(NO);
            }
        }
        
    } failure:^(NSError *err) {
        if (result) {
            result(NO);
        }
    }];
}
#pragma mark 取消收藏
- (void)delCollectionByUid:(NSString *)uid token:(NSString *)token type:(NSString *)type targetId:(NSString *)targetId complete:(void (^)(BOOL))result {
    [AFHttpTool delCollectionByUid:uid token:token type:type targetId:targetId success:^(id response) {
        NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
        if (result) {
            if ([returnCode isEqualToString:@"00"]) {
                dispatch_async(dispatch_get_main_queue(), ^(void) {
                    result(YES);
                });
                
            } else {
                result(NO);
            }
        }
    } failure:^(NSError *err) {
        if (result) {
            result(NO);
        }
    }];
}
#pragma mark 查看收藏列表
- (void)queryMyCollectionByUid:(NSString *)uid token:(NSString *)token pageSize:(NSString *)pageSize pageNum:(NSString *)pageNum complete:(void (^)(NSMutableArray *))collectionListArray {
    NSMutableArray *list = [NSMutableArray new];
    [AFHttpTool queryMyCollectionByUid:uid token:token pageSize:pageSize pageNum:pageNum success:^(id response) {
        NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
        if (collectionListArray) {
            if ([returnCode isEqualToString:@"00"]) {
//                NSArray *dataArray = response[@"res"];
//                for (NSDictionary * dic in dataArray) {
//                    HQCollectModel *collectionModel = [HQCollectModel new];
//                    collectionModel.commentCnt = ((NSNumber *)dic[@"commentCnt"]).stringValue;
//                    collectionModel.createTime = dic[@"createTime"];
//                    collectionModel.headImg = dic[@"headImg"];
//                    collectionModel.likeCnt = ((NSNumber *)dic[@"likeCnt"]).stringValue;
//                    collectionModel.nickName = dic[@"nickName"];
//                    collectionModel.type = ((NSNumber *)dic[@"type"]).integerValue;
//                    collectionModel.targetId = ((NSNumber *)dic[@"targetId"]).stringValue;
//                    collectionModel.urls = dic[@"urls"];
//                    if ([dic.allKeys containsObject:@"prevImgUrl"]) {
//                        collectionModel.prevImgUrl = dic[@"prevImgUrl"];
//                    }
//                    [list addObject:collectionModel];
                    
//                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    collectionListArray(list);
                });
                
            } else {
                collectionListArray(list);
            }
        }
        
    } failure:^(NSError *err) {
        if (collectionListArray) {
            collectionListArray(list);
        }
    }];
    
}
#pragma mark 更新用户信息
- (void)updateUserInfoByUid:(NSString *)uid token:(NSString *)token nickName:(NSString *)nickName myCheck:(NSString *)myCheck background:(NSString *)background complete:(void (^)(BOOL))result {
    [AFHttpTool updateUserInfoByUid:uid
                              token:token
                           nickName:nickName
                            myCheck:myCheck
                         background:background
                            success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 
             } else {
                 result(NO);
             }
         }
         
     }
                            failure:^(NSError *err)
     {
         if (result) {
             result(NO);
         }
     }];
}
#pragma mark 删除摄影
- (void)delPhotoByUid:(NSString *)uid token:(NSString *)token photoId:(NSInteger)photoId complete:(void (^)(BOOL))result {
    [AFHttpTool delPhotoByUid:uid
                        token:token
                      photoId:photoId
                      success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 
             } else {
                 result(NO);
             }
         }
     }
                      failure:^(NSError *err)
     {
         if (result) {
             result(NO);
         }
     }];
}
#pragma mark 删除视频
- (void)delVideoByUid:(NSString *)uid token:(NSString *)token videoId:(NSInteger)videoId complete:(void (^)(BOOL))result {
    [AFHttpTool delVideoByUid:uid
                        token:token
                      videoId:videoId
                      success:^(id response)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",response[@"returnCode"]];
         if (result) {
             if ([returnCode isEqualToString:@"00"]) {
                 dispatch_async(dispatch_get_main_queue(), ^(void) {
                     result(YES);
                 });
                 
             } else {
                 result(NO);
             }
         }
     }
                      failure:^(NSError *err)
     {
         if (result) {
             result(NO);
         }
         
     }];
}
@end
